<template>
	<el-dialog :visible.sync="options.showDialog" width="600px">
		<!-- 数据移交表单 -->
		<el-form ref="Form" :model="form" label-width="100px" class="search">
			<h3 class="title">{{options.title}}</h3>
			<el-form-item label="交接账号" v-if="options.type == '移交'">
				<el-select v-model="form.newUserId" placeholder="请选择标注类型" clearable>
					<el-option v-for="(item,index) in accountList" :key="index" :label="item.accountNumber"
						:value="item.userId"></el-option>
				</el-select>
			</el-form-item>
			<div v-if="options.title == '编辑项目'||options.type == '新增项目'">
				<el-form-item label="岗位">
					<el-input v-model="positionName"></el-input>
				</el-form-item>
				<el-form-item label="企业">
					<el-input v-model="companyName"></el-input>
				</el-form-item>
				<el-form-item label="招聘渠道">
					<el-select v-model="recruitmentChannel" multiple filterable allow-create default-first-option
						style="width: 300px;" placeholder="请输入招聘渠道">
						<el-option v-for="item in optionsList" :key="item" :label="item" :value="item">
						</el-option>
					</el-select>
				</el-form-item>


				<el-form-item label="备注">
					<el-input type="textarea" v-model="mark"></el-input>
				</el-form-item>
				<p class="tips" v-if="options.tips">{{options.tips}}</p>
				<el-form-item label="操作:">
					<el-radio-group v-model="oprations">
						<el-radio label="1" class="jinji">紧急</el-radio>
						<el-radio label="2" class="zhengchang">正常</el-radio>
						<el-radio label="3" class="zhangting">暂停</el-radio>
					</el-radio-group>
				</el-form-item>
			</div>
			<div v-if="options.title == '新增电话招聘'||options.type == '编辑电话招聘'">
				<el-form-item label="姓名">
					<el-input v-model="phoneUserName"></el-input>
				</el-form-item>
				<el-form-item label="手机号">
					<el-input v-model="tel"></el-input>
				</el-form-item>
				<el-form-item label="账号">
					<el-input v-model="account"></el-input>
				</el-form-item>
				<p class="tips" v-if="options.tips">{{options.tips}}</p>

			</div>





			<p class="restPwd" v-show="options.title == '重置密码'">是否确认为该用户<span style="color: red;">重置密码</span></p>


			<div class="sub">
				<el-button size="small" style="min-width: 100px;background-color: #5492CC;color: #fff;" @click="sub">确定
				</el-button>
			</div>
		</el-form>
	</el-dialog>
</template>

<script>
	export default {
		props: {
			options: {
				mark: '',
				require: true,
				type: Object
			}
		},
		data() {
			return {
				phoneUserName: '',
				tel: '',
				account: '',
				recruitmentChannel: '',
				positionName: '',
				oprations: '1',
				mark: '',
				proejctId: '',
				formList: [],
				optionsList: [],
				companyName: '',
				form: {
					newUserId: '', //要移交给谁
					companyName: '',
					positionName: '',
					recruitmentChannel: [],
				},
				accountList: [], //全部账号列表
				projectList: [], //项目列表
			}
		},
		mounted() {
			this.formList = this.options.dialogContent;
		},
		methods: {
			//提交数据
			sub() {
				if (this.options.title == '编辑项目' || this.options.type == '新增项目') {
					this.form.mark = this.options.mark
					let params = {
						companyName: this.companyName, //公司名
						positionName: this.positionName, //岗位名
						projectRemark: this.mark, //备注
						suspendStatus: this.oprations, //状态
						// : this.recruitmentChannel  ,//渠道
						rlist: this.recruitmentChannel
					}
					console.log(this.recruitmentChannel.length);
					if (this.recruitmentChannel.length == 0) {
						return this.$message.error('招聘渠道不能为空！！！！')
					}
					if (this.companyName == '' || this.positionName == '' || this.projectRemark == '' || this
						.suspendStatus == '' || this.suspendStatus == '') {
						this.$message.error('请将数据填写完整！！！')
						return false
					}
					let url = '/v1/librarian/insertProject';
					//  this.inputData.title = '编辑项目';
					if (this.options.title == '编辑项目') {
						url = '/v1/librarian/updateProject';
						params.projectId = this.projectId
					}else if(this.options.title == '新增项目'){
						params.projectId =''
					}
					this.$telAxios.post(url, params).then(res => {
						this.recruitmentChannel = []
						if (res.data.code == 1000) {
							this.$emit('subData', data);
							return this.$message.success('操作成功！！！')
						} else {
							if (res.data.code == 1) {
								this.$emit('subData', data);
								return this.$message.success('操作成功！！！')
							} else {
								return this.$message.error(res.data.message)
							}

							return this.$message.error(res.data.message)
						}
						if (res.data.code == 1) {
							this.$emit('subData', data);
							return this.$message.success('操作成功！！！')
						} else {
							if (res.data.code == 1000) {
								this.$emit('subData', data);
								return this.$message.success('操作成功！！！')
							} else {
								return this.$message.error(res.data.message)
							}

							return this.$message.error(res.data.message)
						}






					})

				}

				let data = {
					name: this.phoneUserName, //姓名
					telnum: this.tel, //手机号
					accountNumber: this.account, //账号
					status: "1", //注销传2
					passWord: "admin@123" //重置密码时传入admin@123
				}
				if (this.options.title == '新增电话招聘') {


				} else if (this.options.title == '编辑电话招聘' || this.options.title == '重置密码') {
					data.userId = this.options.data.userId
				}
				this.$emit('subData', data);

			},
			//获取账户数据
			getAccountData() {
				let params = {};
				this.$telAxios.post('/v1/librarian/selectFlexibileUserInfoListNotPage', params).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						res.data.data.flist.forEach((item, index) => {
							if (item.accountNumber == this.options.userInfo.accountNumber) {
								res.data.data.flist.splice(index, 1);
							}
						})
						this.accountList = res.data.data.flist;
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
			},
			getChange(data) {
				console.log(data);

			},
			//获取项目数据
			getProjectList() {
				this.$telAxios.post('/v1/librarian/selectProjectByListNotPage', {}).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						this.projectList = res.data.data.plist;
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
			}
		},
		watch: {
			'options.showDialog'() {

				if (this.options.showDialog) {
					this.optionsList = this.options.recruitmentChannel
					this.formList = this.options.dialogContent;
					this.form = this.options.form;
					if (this.options.type == '移交') {
						this.form.transfer = this.options.userInfo.accountNumber;
						this.getAccountData();
					} else if (this.options.type == '新增项目') {
						this.getProjectList();
						this.options.type = '新增项目'
						this.companyName = '' //公司名
						this.positionName = '' //岗位名
						this.mark = '' //备注
						// : this.recruitmentChannel  ,//渠道
						this.recruitmentChannel = []
					} else if (this.options.type == '编辑项目') {
						let data = this.options.data
						this.options.type = '编辑项目'
						this.mark = data.projectRemark
						this.positionName = data.positionName
						this.companyName = data.companyName
						this.recruitmentChannel = this.optionsList
						this.projectId = data.projectId
						if (data.suspendStatus == '暂停') {
							this.oprations = '3'
						} else if (data.suspendStatus == '正常') {
							this.oprations = '2'
						} else {
							this.oprations = '1'
						}

					} else if (this.options.type == '编辑电话招聘') {
						console.log(this.options.data);
						let data = this.options.data
						this.phoneUserName = data.name
						this.tel = data.telnum
						this.account = data.accountNumber
					}
				}
			}
		}
	}
</script>

<style scoped="scoped">
	.search {
		width: 400px;
		margin: 20px auto;
		overflow: hidden;
	}

	.jinji /deep/ .el-radio__input.is-checked .el-radio__inner {
		border-color: red;
		background: red;
	}

	/deep/ .el-radio__input.is-checked+.el-radio__label {
		color: #333333;
	}


	.zhangting /deep/ .el-radio__input.is-checked .el-radio__inner {
		border-color: orange;
		background: orange;
	}

	.search .title,
	.sub {
		text-align: center;
	}

	.restPwd {
		font-size: 26px;
		font-family: PingFang SC;
		font-weight: 300;
		color: #000000;
		text-align: center;
	}

	.tips {
		color: red;
		margin-left: 100px;
	}

	.sub {
		margin: 20px 0;
	}
</style>
